﻿using System.Collections;
using System.Threading;

namespace Infrastructure.Storage
{
    public class ThreadStorageAdapter : IThreadStorage
    {
        public static readonly Hashtable DataContexts = new Hashtable();

        public void Add(string key, object data)
        {
            DataContexts.Add(key + Thread.CurrentThread.Name, data);
        }

        public void Remove(string key)
        {
            key = key + Thread.CurrentThread.Name;

            if (DataContexts.Contains(key + Thread.CurrentThread.Name))
            {
                DataContexts[key + Thread.CurrentThread.Name] = null;
                DataContexts.Remove(key);
            }
        }

        public T Get<T>(string key) where T : class
        {
            return (T)DataContexts[key + Thread.CurrentThread.Name];
        }
    }
}